
//Copyright 1997-2009 Syrinx Development, Inc.
//This file is part of the Syrinx Web Application Framework (SWAF).
// == BEGIN LICENSE ==
//
// Licensed under the terms of any of the following licenses at your
// choice:
//
//  - GNU General Public License Version 3 or later (the "GPL")
//    http://www.gnu.org/licenses/gpl.html
//
//  - GNU Lesser General Public License Version 3 or later (the "LGPL")
//    http://www.gnu.org/licenses/lgpl.html
//
//  - Mozilla Public License Version 1.1 or later (the "MPL")
//    http://www.mozilla.org/MPL/MPL-1.1.html
//
// == END LICENSE ==
using System;
using System.Collections;

using Swaf.Container;

namespace Swaf.DataAccess
{
	/// <summary>
	/// Maintains the results of the MultiAdoNetDataRequest in a
	/// AdoNetDataRequestInfo object.  When asked, it will format the results
	/// of the dar through either the default formatter or a formater provided.
	/// </summary>
	/// <remarks>
	/// This class works closely with MultiAdoNetDataRequest in order to 
	/// manage the extension dars that may be available.  When the Multi-DAR
	/// has extensions and they have results (hasResults="true" in the dar
	/// definition catalog file), the MultiAdoNetDataRequest doesnt execute
	/// the extension dars, this class does.  This is because the db
	/// connection doesnt get released until the formatting gets done if
	/// there are results.  These two classes wait until the main dar is called
	/// and asked to be formatted.</remarks>
	public class MultiAdoNetDataResponse : AdoNetDataResponse
	{
		protected IList m_extendedDars = null;

		public MultiAdoNetDataResponse(AdoNetDataRequestInfo req, string defaultFormatter)
			:base(req, defaultFormatter)
		{
		}

		internal IList ExtendedDars
		{
			set { m_extendedDars = value; }
		}

		public override object formatResults()
		{
			
			object val = base.formatResults();
			if (m_extendedDars != null)
			{
				string mergeName = (MergeListName == null) ? "groupList" : MergeListName;
				FlexiMap m = new FlexiMap();
				m[mergeName] = val;
				NameAddressStack info = new NameAddressStack(m);
				info.push(m_req.PassedInfo);
				foreach (INameAddressSupport dar in m_extendedDars)
					dar.get("", info);
			}
			return val;
		}

		public override System.Data.IDataReader Reader
		{
			get
			{
				return base.Reader;
			}
		}
	}
}
